import Vue from 'vue';
import App from './App.vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from './router';
import store from './store';
import http from './api/home/index';
import './assets/style.css';
import { setToken, removeToken, getToken } from './utils/token';

Vue.prototype.$http = http;
Vue.config.productionTip = false;

if (process.env.NODE_ENV == 'development') require('./mock/mock');

import Timefont from './components/timefont.vue';
import Echarts from './components/Echarts.vue';
import Tabs from './components/tabs.vue';
import Dialog from './components/Dialog.vue';
import Table from './components/table.vue';
import Form from './components/form.vue';
Vue.component('Timefont', Timefont);
Vue.component('Echarts', Echarts);
Vue.component('Tabs', Tabs);
Vue.component('Dialog', Dialog);
Vue.component('Table', Table);
Vue.component('Form', Form);

Vue.use(ElementUI);

router.beforeEach((to, from, next) => {
  const token = getToken();
  if (!token && to.path !== '/login') {
    next('/login');
  } else if (token && to.path == '/login') {
    next('/home');
  } else {
    next();
  }
});

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount('#app');
